'''
Created on Aug 19, 2009

@author: echeek
'''

import math


def permutationGroup(value):
    counts=[0]*10;
    while(value>0):
        counts[value%10]+=1;
        value=int(math.floor(value/10));
    return tuple(counts); 

def Euler52():
    n=0;
    solved=False;
    while not solved:
        n+=1;
        group=permutationGroup(n);
        solved=True;
        for x in range(2,6):
            if group != permutationGroup(n*x):
                solved=False;
                break;
        

    print n;
    
Euler52();